<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin:0;
            padding:0;
        }
        .box {
            height:2000px;
            background:pink;
        }
    </style>
</head>

<body>

    <div class="box">

    </div>
    <script>
        
        var page = 0;
        var flag = true;
        function getData(p) {
            setTimeout(function () {
                console.log('获取下一页数据'+p);
                flag = true;
            },1000)
        }

        window.onscroll = function () {
      
            // debugger;
            // window.scrollTo()

            if (window.scrollY
                 + window.innerHeight 
                 >= 
                 document.body.clientHeight
                 && flag
            ) {
                flag = false;
                page++;
                getData(page);
            }
        }
    </script>
</body>
</html>